﻿using System;
using System.Data;
using System.Windows.Forms;

namespace Common
{
     [Serializable]
     public class PassportInfoData
     {

         private String _TaskCode;

         private String _CardCode;

         private DateTime _Birthday;

         private String _CardID;

         private String _Name;

         private String _OprationNumber;

         private Int32 _Pillar;

         private Int32 _Layer;

         private Int32 _Cell;

         private DateTime _AddTime;

         private String _Operator;

         public String TaskCode
         {
             get{ return _TaskCode;}
             set{ _TaskCode=value;}
         }
         public String CardCode
         {
             get{ return _CardCode;}
             set{ _CardCode=value;}
         }
         public DateTime Birthday
         {
             get{ return _Birthday;}
             set{ _Birthday=value;}
         }
         public String CardID
         {
             get{ return _CardID;}
             set{ _CardID=value;}
         }
         public String Name
         {
             get{ return _Name;}
             set{ _Name=value;}
         }
         public String OprationNumber
         {
             get{ return _OprationNumber;}
             set{ _OprationNumber=value;}
         }
         public Int32 Pillar
         {
             get{ return _Pillar;}
             set{ _Pillar=value;}
         }
         public Int32 Layer
         {
             get{ return _Layer;}
             set{ _Layer=value;}
         }
         public Int32 Cell
         {
             get{ return _Cell;}
             set{ _Cell=value;}
         }
         public DateTime AddTime
         {
             get{ return _AddTime;}
             set{ _AddTime=value;}
         }
         public String Operator
         {
             get{ return _Operator;}
             set{ _Operator=value;}
         }
         public ListViewItem ViewItem;
         public PassportInfoData()
         {
             _TaskCode="";
             _CardCode="";
             _Birthday=DateTime.Now;
             _CardID="";
             _Name="";
             _OprationNumber="";
             _Pillar=0;
             _Layer=0;
             _Cell=0;
             _AddTime=DateTime.Now;
             _Operator="";
             ViewItem=null;
         }
     }

     public class PassportInfoDataFactory
     {
         public static PassportInfoData Construct(IDataReader reader)
         {
             PassportInfoData data = new PassportInfoData();

             data.TaskCode = Convert.ToString(reader["TaskCode"]) ;

             data.CardCode = Convert.ToString(reader["CardCode"]) ;

             data.Birthday = Convert.ToDateTime(reader["Birthday"]) ;

             data.CardID = Convert.ToString(reader["CardID"]) ;

             data.Name = Convert.ToString(reader["Name"]) ;

             data.OprationNumber = Convert.ToString(reader["OprationNumber"]) ;

             data.Pillar = Convert.ToInt32(reader["Pillar"]) ;

             data.Layer = Convert.ToInt32(reader["Layer"]) ;

             data.Cell = Convert.ToInt32(reader["Cell"]) ;

             data.AddTime = Convert.ToDateTime(reader["AddTime"]) ;

             data.Operator = Convert.ToString(reader["Operator"]) ;

             return data;
         }
         public static PassportInfoData Construct(DataTable dt)
         {
             PassportInfoData data = new PassportInfoData();
             if (dt.Rows.Count == 0)
                 return null;
             DataRow dr=dt.Rows[0];

             if(dr==null)

                 return null;

             try{ data.TaskCode = Convert.ToString(dr["TaskCode"]) ;} catch { } 

             try{ data.CardCode = Convert.ToString(dr["CardCode"]) ;} catch { } 

             try{ data.Birthday = Convert.ToDateTime(dr["Birthday"]) ;} catch { } 

             try{ data.CardID = Convert.ToString(dr["CardID"]) ;} catch { } 

             try{ data.Name = Convert.ToString(dr["Name"]) ;} catch { } 

             try{ data.OprationNumber = Convert.ToString(dr["OprationNumber"]) ;} catch { } 

             try{ data.Pillar = Convert.ToInt32(dr["Pillar"]) ;} catch { } 

             try{ data.Layer = Convert.ToInt32(dr["Layer"]) ;} catch { } 

             try{ data.Cell = Convert.ToInt32(dr["Cell"]) ;} catch { } 

             try{ data.AddTime = Convert.ToDateTime(dr["AddTime"]) ;} catch { } 

             try{ data.Operator = Convert.ToString(dr["Operator"]) ;} catch { } 

             return data;
         }
         public static PassportInfoData Construct(DataTable dt, int rowIndex)
         {
             PassportInfoData data = new PassportInfoData();
             if (dt.Rows.Count < rowIndex + 1)
                 return null;
             DataRow dr = dt.Rows[rowIndex];

             if (dr == null)

                 return null;

             try { data.TaskCode = Convert.ToString(dr["TaskCode"]); }
             catch { }

             try { data.CardCode = Convert.ToString(dr["CardCode"]); }
             catch { }

             try { data.Birthday = Convert.ToDateTime(dr["Birthday"]); }
             catch { }

             try { data.CardID = Convert.ToString(dr["CardID"]); }
             catch { }

             try { data.Name = Convert.ToString(dr["Name"]); }
             catch { }

             try { data.OprationNumber = Convert.ToString(dr["OprationNumber"]); }
             catch { }

             try { data.Pillar = Convert.ToInt32(dr["Pillar"]); }
             catch { }

             try { data.Layer = Convert.ToInt32(dr["Layer"]); }
             catch { }

             try { data.Cell = Convert.ToInt32(dr["Cell"]); }
             catch { }

             try { data.AddTime = Convert.ToDateTime(dr["AddTime"]); }
             catch { }

             try { data.Operator = Convert.ToString(dr["Operator"]); }
             catch { }

             return data;
         }
     }
}